package com.changer.common.vo; 

import java.text.SimpleDateFormat;
import java.util.Date;

import com.changer.framework.util.DateTimeUtils;

/** 
 * @author jiwei.guo 
 */
public final class RedisConstants {

	public static final String KEY_DELIMITER = ":";

	public static final String KEY_DOT = ".";
	
	public static final String UPLOAD_ACTION = "upload";
	
	public static final String EQUIPMENT_KEY = "equipment";
	
	public static final String LOGIN_ACTION = "login";
	
	public static final String LOGIN_USER_ACTION = "loginUser";

	public static final String LASER_FILE_SUFFIX = "la";

	public static final String ORIGINAL_FILE_SUFFIX = "or";

	public static final String KEY_FILE_PREFIX = "file";

	public static final String KEY_UPLOAD_FILE_PREFIX = "upload";

	public static final String KEY_PROCESS_IMG_PREFIX = "process";

	public static final String KEY_LOGIN_PREFIX = "login";

	public static final String KEY_MAIL = "mail";

	public static final String KEY_MOBILE = "mobile";

	/**
	 * 获取呆处理的key
	 * @param equipmentUID
	 * @param fileTimestamp
	 * @return
	 */
	public static String getProcessKey(String equipmentUID, String fileTimestamp){
		return equipmentUID + KEY_DELIMITER + fileTimestamp;
	}
	
	/**
	 * 获取今日设备key
	 * @return
	 */
	public static String getDailyEquipmentKey(){
		return DateTimeUtils.formatDateToString(new Date()) + KEY_DELIMITER + EQUIPMENT_KEY;
	}
	
	/**
	 * 获取指定日期设备key
	 * @return
	 */
	public static String getDailyEquipmentKey(Date date){
		return DateTimeUtils.formatDateToString(date) + KEY_DELIMITER + EQUIPMENT_KEY;
	}
	
	/**
	 * 获取今日上传的key
	 * @return
	 */
	public static String getDailyUploadKey(){
		return DateTimeUtils.formatDateToString(new Date()) + KEY_DELIMITER + UPLOAD_ACTION;
	}
	
	/**
	 * 获取指定日期上传的key
	 * @return
	 */
	public static String getDailyUploadKey(Date date){
		return DateTimeUtils.formatDateToString(date) + KEY_DELIMITER + UPLOAD_ACTION;
	}
	
	/**
	 * 获取指定设备今日上传的key
	 * @return
	 */
	public static String getEquipmentUploadKey(String equipmentUID){
		return DateTimeUtils.formatDateToString(new Date()) + KEY_DELIMITER + UPLOAD_ACTION  + KEY_DELIMITER + equipmentUID;
	}
	
	/**
	 * 获取指定设备指定日期上传的key
	 * @return
	 */
	public static String getEquipmentUploadKey(String equipmentUID, Date date){
		return DateTimeUtils.formatDateToString(date) + KEY_DELIMITER + UPLOAD_ACTION  + KEY_DELIMITER + equipmentUID;
	}
	
	/**
	 * 获取今日登录的key
	 * @return
	 */
	public static String getDailyLoginKey(){
		return DateTimeUtils.formatDateToString(new Date()) + KEY_DELIMITER + LOGIN_ACTION;
	}
	
	/**
	 * 获取指定日期登录的key
	 * @return
	 */
	public static String getDailyLoginKey(Date date){
		return DateTimeUtils.formatDateToString(date) + KEY_DELIMITER + LOGIN_ACTION;
	}
	
	/**
	 * 获取今日登录用户的key
	 * @return
	 */
	public static String getDailyLoginUserKey(){
		return DateTimeUtils.formatDateToString(new Date()) + KEY_DELIMITER + LOGIN_USER_ACTION;
	}
	
	/**
	 * 获取指定日期登录用户的key
	 * @return
	 */
	public static String getDailyLoginUserKey(Date date){
		return DateTimeUtils.formatDateToString(date) + KEY_DELIMITER + LOGIN_USER_ACTION;
	}

	/**
	 * 获取待处理图片的key
	 * @param equipmentUID
	 * @param fileTimestamp
	 * @param flag	true为原图，false为激光图
	 * @return
	 */
	public static String getProcessPicKey(String equipmentUID, String fileTimestamp, boolean flag){
		String key;
		if(flag){
			key = KEY_FILE_PREFIX + KEY_DELIMITER + equipmentUID + KEY_DELIMITER + fileTimestamp + KEY_DOT + ORIGINAL_FILE_SUFFIX;
		}else{
			key = KEY_FILE_PREFIX + KEY_DELIMITER + equipmentUID + KEY_DELIMITER + fileTimestamp + KEY_DOT + LASER_FILE_SUFFIX;
		}
		return key;
	}

	/**
	 * 获取待处理图片的key
	 * @param u_id
	 * @param flag	true为修改捆绑手机，false为修改捆绑邮箱
	 * @return
	 */
	public static String getPassportBindingKey(Long u_id, boolean flag){
		String key;
		if(flag){
			key =  String.valueOf(u_id) + KEY_DELIMITER + KEY_MOBILE;
		}else{
			key =  String.valueOf(u_id) + KEY_DELIMITER + KEY_MAIL;
		}
		return key;
	}

	/**
	 * 获取图像上传文件的Key
	 * @param userId
	 * @param fileName
	 * @param flag true为激光图，false为原图
	 * @return
	 */
	public static String getImgFtpUploadFileKey(String userId,String fileName,Boolean flag){
		userId = userId.replaceFirst("^0*", "");
		String deviceId = fileName.substring(0,fileName.indexOf("_"));
		String result = KEY_UPLOAD_FILE_PREFIX + KEY_DELIMITER + userId + KEY_DELIMITER + deviceId + KEY_DELIMITER + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + KEY_DOT;
		if(flag){
			result += LASER_FILE_SUFFIX;
		}else{
			result += ORIGINAL_FILE_SUFFIX;
		}
		return result;
	}

	/**
	 * 获取图像处理统计的Key
	 * @param userId
	 * @param modeType
	 * @return
	 */
	public static String getImgProcessKey(String userId,String modeType,String startTime,String ossOrKey){
		String deviceId = ossOrKey.substring(0,ossOrKey.indexOf("_"));
		String key = KEY_PROCESS_IMG_PREFIX + KEY_DELIMITER + userId + KEY_DELIMITER + deviceId + KEY_DELIMITER + startTime + KEY_DOT + modeType;
		return key;
	}

	/**
	 * 获取用户登录统计的Key
	 * @param loginIp
	 * @param loginTime
	 * @param app
	 * @return
	 */
	public static String getLoginKey(String app,String loginIp,String loginTime){
		String key = KEY_LOGIN_PREFIX + KEY_DELIMITER + app + KEY_DELIMITER + loginIp + KEY_DELIMITER + loginTime;
		return key;
	}

}
